<template>
  <div class="h_100 nav_menu">
    <h1><img src="../assets/logo.png" alt=""></h1>
    <ul class="nav_box">
      <li
        @click="gotoPath(item, index)"
        :class="navIndex == index ? 'active' : ''"
        v-for="(item, index) in navData"
        :key="index"
      >
        <img :src="item.meta.imgurl" alt="" />
        <p>{{ item.meta.title }}</p>
      </li>
    </ul>
    <div class="userinfo">
      <div class="userinfo_img">
        <img src="@/assets/header.png" alt="" />
      </div>
      <h3>Alice</h3>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
export default {
  name: "NavMenu",
  data() {
    return {
      navIndex: 0,
      navData: [
        {
          name: "Home",
          path: "/index",
          headerTitle: "友邦保险",
          meta: {
            title: "首页",
            icon: "",
            imgurl: require("@/views/home/img1/index_iocn.png"),
          },
        },
        {
          name: "TalentPool",
          path: "/talentpool",
          headerTitle: "人才库",
          meta: {
            title: "人才库",
            icon: "",
            imgurl: require("@/views/home/img1/rck_con.png"),
          },
        },
        {
          name: "",
          path: "",
          headerTitle: "增员看板",
          meta: {
            title: "增员看板",
            icon: "",
            imgurl: require("@/views/home/img1/zykb_icon.png"),
          },
        },
        {
          name: "Evaluation",
          path: "/evaluation",
          headerTitle: "天生赢家",
          meta: {
            title: "天生赢家",
            icon: "",
            imgurl: require("@/views/home/img1/tsyj_icon.png"),
          },
        },
        {
          name: "",
          path: "",
          headerTitle: "视频墙",
          meta: {
            title: "视频墙",
            icon: "",
            imgurl: require("@/views/home/img1/spq_icon.png"),
          },
        },
        {
          name: "/addProspectiveStaff",
          path: "AddProspectiveStaff",
          headerTitle: "增员邀约",
          meta: {
            title: "增员宝",
            icon: "",
            imgurl: require("@/views/home/img1/zyb_icon.png"),
          },
        },
      ],
    };
  },
  watch: {
    router(val){
      console.log(val.meta.title)
      this.navData.map((item,index)=>{
        if(val.meta.title == item.headerTitle){
          this.navIndex = index;
        }
      })
    }
  },
  computed: {
    router() {
      return this.$route
    },
  },
  methods: {
    gotoPath(item, index) {
      if (!item.path) {
        return Toast("该模块开发中……");
      }
      this.navIndex = index;
      if (this.$router.history.current.name == item.name) return false;
      this.$router.push({
        path: item.path,
      });
    },
  },
};
</script>
<style lang="less" scoped>
.nav_menu {
  min-width: 1rem;
  h1 {
    width: 100%;
    height: 1.06rem;
    display: flex;
    justify-content: center;
    align-items: center;
    img{
      width: 0.37rem;
      display: block;
    }
  }
  .nav_box {
    height: calc(100% - 2.16rem);
    overflow-y: auto;
    li {
      height: 0.52rem;
      display: flex;
      align-items: center;
      color: #fff;
      border-left: 0.04rem solid transparent;
      i {
        font-size: 0.16rem;
        margin-left: 0.09rem;
        margin-right: 0.08rem;
      }
      img {
        width: 0.16rem;
        display: block;
        margin-left: 0.1rem;
        margin-right: 0.08rem;
      }
      p {
        font-size: 0.12rem;
      }
    }
    li.active {
      border-left-color: #fff;
      background-color: rgba(255, 255, 255, 0.2);
    }
  }
  .userinfo {
    height: 1.1rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    .userinfo_img {
      width: 0.44rem;
      height: 0.44rem;
      padding: 0.02rem;
      overflow: hidden;
      border-radius: 0.44rem;
      background-image: linear-gradient(179deg, #ec257b 0%, #d41045 99%);
      margin-bottom: 0.08rem;
      img {
        width: 100%;
        display: block;
      }
    }
    h3 {
      font-size: 0.18rem;
      color: #ffffff;
    }
  }
}
</style>